package LC;

/**
 * https://leetcode.com/problems/excel-sheet-column-number/description/
 * Related to question Excel Sheet Column Title
 * Given a column title as appear in an Excel sheet, return its corresponding column number.
 * For example:
 * A -> 1
 * B -> 2
 * C -> 3
 * ...
 * Z -> 26
 * AA -> 27
 * AB -> 28
 */
public class LC_171_ExcelSheetColumnNumber_String {
    public static void main(String[] args) {
        System.out.println(Solution.titleToNumber("AZ"));
    }

    static class Solution {
        static int titleToNumber(String s) {
            int len = s.length();
            int result = 0;
            for (int i = len - 1; i >= 0; i--) {
                result += (s.charAt(i) - 'A' + 1) * Math.pow(26, len - 1 - i);
            }
            return result;
        }
    }
}